import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

import PurgeIcons from 'vite-plugin-purge-icons'

import VueSetupExtend from 'vite-plugin-vue-setup-extend'

import ViteImages from 'vite-plugin-vue-images'

import * as path from 'path'

const resolve = (p) => {
  return path.resolve(__dirname, p)
}

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue({
      // reactivityTransform: true
    }),
    VueSetupExtend(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
      // dts: 'src/auto-imports.d.ts',
      imports: ['vue']
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
    PurgeIcons({
      /* PurgeIcons Options */
      content: [
        '**/*.html',
        '**/*.js',
        '**/*.vue',
      ]
    }),
    ViteImages({
      dirs: ['src/assets/images'] // 指明图片存放目录
    })
  ],
  resolve: {
    alias: {
      '@': resolve('./src')
    }
  },
  server: {
    open: true,
    port: 9033,
    proxy: {
      '/api': {
        target: 'https://api2.ujuji.com',
        changeOrigin: true,
        rewrite: path => path.replace(/^\/api/, '')
      }
    },
    cors: true,
  }
})
